﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZZT
{
    public class Heap
    {
        int counter;
        Dictionary<int, byte[]> table;

        public Heap()
        {
            table = new Dictionary<int, byte[]>();
            Clear();
        }

        virtual public int Allocate(byte[] data)
        {
            counter++;
            byte[] clonedData = new byte[data.Length];
            Array.Copy(data, clonedData, clonedData.Length);
            table[counter] = clonedData;
            return counter;
        }

        public void Clear()
        {
            counter = int.MinValue;
            table.Clear();
        }

        virtual public void Free(int handle)
        {
            if (table.ContainsKey(handle))
                table.Remove(handle);
        }
    }
}
